
Ext.ns("Extmx.form");

Extmx.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
    initComponent : function(){
       	Extmx.form.SearchField.superclass.initComponent.call(this);
        this.addEvents('buscar','borrar')
        this.on('specialkey', function(f, e){
            if(e.getKey() == e.ENTER){
                this.onTrigger2Click();
            }
        }, this);
    },
    searchWithEmptyString:false,
    validationEvent:false,
    validateOnBlur:false,
    trigger1Class:'x-form-clear-trigger',
    trigger2Class:'x-form-search-trigger',
    hideTrigger1:true,
    width:180,
    hasSearch : false,
    onTrigger1Click : function(){
        if(this.hasSearch){
            this.el.dom.value = '';            
            this.triggers[0].hide();
            this.hasSearch = false;
            this.fireEvent('borrar',this);
        }
    },

    onTrigger2Click : function(){
        var v = this.getRawValue();
        if(v.length < 1 && !this.searchWithEmptyString){
            this.onTrigger1Click();
            return;
        }
        this.hasSearch = true;
        this.triggers[0].show();
        this.fireEvent('buscar',this,v);
    },

    showTrigger1: function (){
        this.hasSearch = true;
        this.triggers[0].show();
    }
});
Ext.reg('searchfieldmx',Extmx.form.SearchField);